package com.colin.app.adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.colin.app.R;
import com.colin.app.bean.ItemBean;
import com.colin.library.adapter.BaseAdapter;
import com.colin.library.help.ImageLoader;

import java.util.List;

/**
 * Created by Colin on 2017/2/14.
 */

public class ListAdapter extends BaseAdapter<ItemBean> {
    public ListAdapter(Activity activity, List<ItemBean> itemList) {
        super(activity, itemList);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder = null;
        //优化2 :判断是否有缓存
        if (null == convertView) {
            holder = new ViewHolder();
            convertView = this.layoutInflater.inflate(R.layout.item_itembean_list, viewGroup, false);
            holder.image_itembean_background = (ImageView) convertView.findViewById(R.id.image_itembean_background);
            holder.text_itembean_title = (TextView) convertView.findViewById(R.id.text_itembean_title);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ImageLoader.getInstance().loadImageByGlide(holder.image_itembean_background, itemList.get(position).getImageLarge());
        holder.text_itembean_title.setText(itemList.get(position).getTitle());
        return convertView;
    }

    //优化1:ViewHolder模式
    public final class ViewHolder {
        public ImageView image_itembean_background;
        public TextView text_itembean_title;
    }
}
